Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature: sort queryparams can be relationship fileds #111

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

babywolfh
Copy link

sort queryparams can be relationship fileds

huangzhuo added 3 commits August 15, 2018 16:01
sort queryparams can be relationship fileds
1. delete sort relationship exception
2. add a case to test get list with relationship sort queryparams
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 93.52% when pulling 05106a4 on babywolfh:sort_relationships into 268e948 on miLibris:master.

@akira-dev
Copy link
Collaborator

akira-dev commented Jan 22, 2019

I think it is a good start to implement sorting on relationship fields but it would be better that you can specify the related field to sort on instead of only use to related "id" field. ex:

{'field': field, 'order': order, 'relationship_field': related_field}

if sort_opt['relationship']:
relationField = getattr(self.model, field)
relationClass = relationField.mapper.class_
query = query.join(relationField).order_by(getattr(getattr(relationClass, 'id'), sort_opt['order'])())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is not good to use the id field because it can not exists. For example I never name my primary keys as id.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants